package adapters;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.administrator.newxlmedical.R;

import java.util.ArrayList;

/**
 * Created by admin on 2018/1/15.
 */
public class BitmapActivityPagerAdapter extends PagerAdapter {
    ArrayList<String> imagePath;
    Context context;

    public BitmapActivityPagerAdapter(ArrayList<String> imagePath, Context context) {
        this.imagePath = imagePath;
        this.context = context;
    }

    @Override
    public int getCount() {
        return imagePath.size();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager) container).removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View imagelayout = LayoutInflater.from(context).inflate(R.layout.viewpager_bitmap_activity_layout, null);
        ImageView imageview = (ImageView) imagelayout.findViewById(R.id.iv_viewpager_bitmap_activity);
//        Target<Drawable> into = Glide.with(context).load(imagePath.get(position)).into(imageview);
        RequestOptions options = new RequestOptions().placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher);
        Glide.with(context).load(imagePath.get(position)).apply(options).into(imageview);
        ((ViewPager) container).addView(imagelayout);
        return imagelayout;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}
